package com.houtai.common.util;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

public class SendMessageUtil {
    /**
     * 发送注册短信
     * @param phone_no
     * @param code
     * @return
     */
    public static boolean setRegisterSms( String phone_no, String code) {
        boolean flag = false;
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAIm08Hw6XUBv6x", "akwzd97Nbj8HH5Kgx3Ec732AYpL51q");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setMethod(MethodType.POST);
        request.setDomain("dysmsapi.aliyuncs.com");
        request.setVersion("2017-05-25");
        request.setAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", phone_no);
        request.putQueryParameter("SignName", "犇犇有车");
        request.putQueryParameter("TemplateCode", "SMS_133276680");
        request.putQueryParameter("TemplateParam", "{\"code\": " + code + "}");


        try {
            CommonResponse response = client.getCommonResponse(request);
            String  data = response.getData();
            if (data.contains("OK")) {
                flag = true;
            }
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
        return flag;
    }
}
